﻿<!DOCTYPE html>
<html>
<head>
	<title>Benchmark scope lookup</title>
</head>
<body>
	<script type="text/javascript">
		var objTest = {
			root: { x: '', y: '' }
		};
		function str_object() {
			var s = new String('0123456789abcdefghigklmnopqrstuvwxyz');
			for (var i = 0; i < 1000; i++) {
				for (var j = 0; j < s.length; j++) {
					for (var k in objTest.root) {
						objTest.root[k] = s.charAt(j);
					}
				}
			}
		}

		function str_base() {
			var s = '0123456789abcdefghigklmnopqrstuvwxyz';
			for (var i = 0; i < 1000; i++) {
				for (var j = 0; j < s.length; j++) {
					for (var k in objTest.root) {
						objTest.root[k] = s.charAt(j);
					}
				}
			}
		}

		function str_base1() {
			var s = '0123456789abcdefghigklmnopqrstuvwxyz',
					obj = objTest.root;
			for (var i = 0; i < 1000; i++) {
				for (var j = 0, l = s.length; j < l; j++) {
					for (var k in obj) {
						obj[k] = s.charAt(j);
					}
				}
			}
		}

		function str_base2() {
			var s = '0123456789abcdefghigklmnopqrstuvwxyz',
					obj = objTest.root;
			var j, l, k;
			for (var i = 0; i < 1000; i++) {
				for (j = 0, l = s.length; j < l; j++) {
					for (k in obj) {
						obj[k] = s.charAt(j);
					}
				}
			}
		}

		console.log('Profiling will begin in 2 seconds...');
		setTimeout(function () {
			console.profile();
			for (var i = 0; i < 100; i++) {
				str_object();
				str_base();
				str_base1();
				str_base2();
			}
			console.profileEnd();
		}, 2000);
	</script>
</body>
</html>
